#include <bits\stdc++.h>
using namespace std;

class Solution {
public:
    int longestSubsequence(vector<int>& arr, int difference) {
        unordered_map<int, int> dp;
        int maxn = 0;
        for(auto e: arr){
            dp[e] = dp[e-difference] + 1;
            maxn = max(dp[e], maxn);
        }
        return maxn;
    }
};